home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / comm / irc / HDSearch.lha / HDSearch / HDSearch.amirx next >
Text File  |  1999-01-10  |  12KB  |  289 lines

  1. /*$VER: HDSearch.amirx 3.0 (09.01.99) AmIRC/HardDrive File Finder & Sender  */
  2. /*                                                                          */
  3. /* So Realy what is HDSearch.  HDSeach lets you find files you know that    */ 
  4. /* are on your Harddrives somewheres, but you don't know where. HDSearch    */
  5. /* uses SimpleFind v2.5 by Sebastian Bauer, to search the device given,     */
  6. /* and outputs to AmIRC screen, and allows you to send found files to a     */
  7. /* selected user.  Thanks to Geronimo for all the help on this project.     */
  8. /* Thanks to Sebastian Bauer for making a great program.                    */
  9. /* Made for ^Snoopy^                                                        */
  10. /*                                                                          */
  11. /*                                                                          */
  12. /*   What's it DO: Searches your HardDrives for files                       */
  13. /*                 Allows you to send selected file(s) to a user            */
  14. /*                                                                          */
  15. /*   Requirments:  installed in where every you wish:                       */
  16. /* «Aminet» simplefind.lha     util/dir   216K   9 V2.4 of the FileFinder   */                                    
  17. /*                 installed in LIBS:                                       */
  18. /* «Aminet» RexxTricks_386.lha util/rexx 302K ARexx function library, V38.6 */
  19. /* «Aminet» rexxdossupport.lha util/rexx  31K V3.5 ARexx function lib       */ 
  20. /* «Aminet» KuangEleven25.lha comm/tcp  396K Kuang Eleven 3                 */ 
  21. /*      Only need rexxkuang11.library from KuangEleven if you don't use.    */     
  22. /*                                                                          */
  23. /*   Install:  put this script in Amirc/rexx/                               */
  24. /*                                                                          */
  25. /*   Config:  Add the following alais to amirc list                         */
  26. /*                                                                          */
  27. /*            FFind = /rx HDSearch FFind %p                                 */
  28. /*            FSend = /rx HDSearch FSend %p                                 */
  29. /*            FShow = /rx HDSearch FShow %p                                 */
  30. /*            FINDEX = /rx HDSearch FINDEX blah                             */
  31. /*            UShow = /rx HDSearch UShow %p                                 */
  32. /*                                                                          */
  33. /*    If you uses KuangEleven 3.0 Gamma(25) put HDSearch.reg in             */
  34. /*    AmIRC/events/ and this will enable all the above alaises without      */
  35. /*    you having to add them to AmIRC.                                      */
  36. /*                                                                          */                                               
  37. /*      Fill in Simplefind path below                                       */
  38. /*                                                                          */
  39. /*   Usage:                                                                 */ 
  40. /*                                                                          */ 
  41. /*   /FFind <devicename> <flags>                                            */
  42. /*                                                                          */
  43. /*        - wildcards: "*" stands for none, one or more character(s).       */
  44. /*        ---------- (identical with #? in AMIGA-DOS)                       */
  45. /*                   "?" stands for just one character.                     */
  46. /*                   You can use multiple *s and ?s together!!              */
  47. /*                                                                          */
  48. /*   Flags: HDS flags are the simplefind Shell Arguments                    */
  49. /*          Read Simplefind Guide on Shell usage.                           */
  50. /*                                                                          */
  51. /*          /FFind DH0: PAT=Simple                                          */
  52. /*                                                                          */
  53. /* «HDSearch» 1. SimpleFind.info  System:OPUS  1Kb  21-Jan-98               */
  54. /* «HDSearch» 2. SimpleFindPrefs.info System:OPUS/SimpleFind  1Kb  07-Feb-98*/ 
  55. /* «HDSearch» 3. SimpleFind.info  System:OPUS/SimpleFind 1Kb  30-Aug-98     */
  56. /* «HDSearch» 4. SimpleFindPrefs  System:OPUS/SimpleFind 69Kb  28-Apr-98    */
  57. /* ETC......                                                                */
  58. /*                                                                          */
  59. /* /FSend <%U|nick> 2,3,4 -- will send 2,3,4 to nick                        */
  60. /*                                                                          */
  61. /* /FShow 2,5,7 --- will show 2,5,7 to current channel                      */
  62. /*                                                                          */
  63. /* /UShow <%U|nick> 2,3,4  ---- will show 2,3,4 to User as a private msg    */
  64. /*                                                                          */
  65. /* /Findex --- will show you current indexes you have made                  */
  66. /* Tips:                                                                    */
  67. /*                                                                          */
  68. /* o  You can't send files with spaces in the name.                         */
  69. /* o  Use Simplefinds GUI to create indexes of the DIR you wish to uses.    */
  70. /*                                                                          */
  71. /*                                                                          */
  72. /* Another Great Program by Amiga Coding Syndicate                          */
  73. /*               (ACS) www.surf.to/Amigacs                                  */
  74. /*                                                                          */
  75. /* IRC:Bossman^ Email:bosman@erols.com    http://www.erols.com/bosman       */
  76. /*                                                                          */
  77. /* IRC:GeRonImo Email:geronimo@tpgnet.net http://www.tpgnet.net/a/geronimo/ */
  78. /*--------------------------------------------------------------------------*/
  79.  
  80.  
  81. simplefind = 'Sys:OPUS/simplefind/simplefind'
  82.  
  83.  
  84. /*--------------------------------------------------------------------------*/
  85. libs = "rexxsupport.library rexxdossupport.library rexxtricks.library rexxkuang11.library"
  86.  
  87. DO UNTIL libs='';PARSE VAR libs lib libs;IF EXISTS('libs:'lib)|EXISTS('Libs/'lib)|EXISTS(lib) THEN DO
  88. IF ~show('L',lib) THEN call addlib(lib,0,-30,0);END;ELSE DO;LECHO('Cannot load 'lib);EXIT;END;END
  89.  
  90. OPTIONS RESULTS
  91.  
  92. filein = 'Ram:T/HDsearchfoundfiles.txt'
  93. fileout= 'Ram:T/HDsearchfoundfiles2.txt'
  94.  
  95. PARSE ARG type cmds
  96.  
  97. IF cmds="" THEN DO
  98.   SELECT
  99.    WHEN UPPER(type)="FFIND"   THEN CECHO('Usage: /FFind <dev:> <filename> <flag>') 
  100.    WHEN Upper(type)="FSEND"   THEN CECHO('Usage: /FSend <nick|%U> 1 or 2,3') 
  101.    WHEN Upper(type)="FSHOW"   THEN CECHO('Usage: /FShow 1 or 2,3') 
  102.    WHEN Upper(type)="USHOW"   THEN CECHO('Usage: /UShow <nick|%U> 1 or 2,3') 
  103.    WHEN Upper(type)="FINDEX"   THEN CECHO('Usage: /FINDEX ')
  104.     OTHERWISE CECHO('Not a valid 'bold('HDSearch')' command')
  105.   END
  106.    EXIT
  107. END
  108.  
  109. SELECT
  110.  WHEN UPPER(type) = 'FINDEX' THEN findx()
  111.  WHEN UPPER(type) = 'FFIND' THEN find()
  112.  WHEN UPPER(type) = 'FSEND' THEN send()
  113.  WHEN UPPER(type) = 'USHOW' THEN ushow()
  114.  WHEN UPPER(type) = 'FSHOW' THEN fshow()
  115.   OTHERWISE CECHO('Not a valid 'bold('HDSearch')' command')
  116. END
  117. EXIT
  118.  
  119. findx:
  120. Address command simplefind 'AI >T:simpleindex.txt'
  121. READFILE('T:simpleindex.txt','SI')
  122. CECHO('Available Simplefind/HDSearch indexes')
  123. DO x = 1 to si.0
  124.  CECHO(si.x)
  125. END
  126. EXIT
  127.  
  128. FIND:
  129. PARSE VAR cmds srchpath flags
  130. srchpath2 = PATHPART(srchpath)
  131.  
  132. /* need to find search pattern in Com and Pat */
  133.  
  134. If POS('PAT=',UPPER(flags))> 0 then do
  135.    parse var flags blah'='filename .
  136.    CECHO('Searching for 'bold(filename)' in dir/path 'BOLD(srchpath))
  137. END
  138.  
  139. If POS('COM=',UPPER(flags))> 0 & POS('PAT=',UPPER(flags)) = 0 then do
  140.    parse var flags blah'='filename .
  141.    CECHO('Searching Comments for 'bold(filename)' in dir/path 'BOLD(srchpath))
  142. END
  143.  
  144.  
  145. If POS('BETWEEN=',UPPER(flags))>0 & POS('COM=',UPPER(flags))=0 & POS('PAT=',UPPER(flags))=0 then do
  146.    parse var flags blah'='filename .
  147.    CECHO('Searching for file Between 'bold(filename)' in dir/path 'BOLD(srchpath))
  148.    filename = 'Files Bewteen 'filename
  149. END
  150.  
  151. if filename="FILENAME" then filename='Unkown'
  152.  
  153. TIME(E)
  154.  
  155. IF ~EXISTS(srchpath2) THEN DO;CECHO(BOLD(srchpath) 'is not a valid device/path');EXIT;END
  156.  
  157. CECHO('Please be patient this may take some time')  
  158.  Address command simplefind srchpath2 flags 'LFORMAT "%p%n %l %d" >'filein
  159.  CHECKSIZE()
  160.    OPEN(file2,fileout,'W')
  161.    OPEN(file,filein,'R')
  162.     x=0
  163.     DO UNTIL EOF(file)
  164.      line = READLN(file)
  165.       x=x+1
  166.       IF line = '' THEN leave
  167.          numwords = WORDS(line)
  168.          date = WORD(line,numwords)
  169.          size = WORD(line,numwords-1)
  170.          line = DELWORD(line,numwords-1,2)
  171.          parse var line drive":"fileline 
  172.            IF WORDS(drive) > 1 THEN do
  173.               HDdatafile = 'T:HDS-drivelist.txt'
  174.               Address Command 'C:info > 'HDdatafile
  175.                OPEN(HDfile,HDdatafile,'R')
  176.                   DO UNTIL EOF(HDfile)
  177.                    line = READLN(HDfile)
  178.                   IF POS(UPPER(drive),UPPER(line)) > 0 THEN DO
  179.                      drive = COMPRESS(WORD(line,1),':')
  180.                      LEAVE
  181.                     END
  182.                    END 
  183.            END
  184.        CLOSE(HDfile)
  185.        DELETE(HDdatafile)  
  186.          fp=FILEPART(drive':'fileline)
  187.          ndir=PATHPART(drive':'fileline)
  188.          size = realsize(size)
  189.          newline = x'. 'fp' -- 'ndir'  'size'  'date
  190.          WRITELN(file2,newline)
  191.          cecho(bold(x)'. 'fp' 'ndir'  'size'  'date)
  192. END
  193.        CLOSE(file)
  194.        CLOSE(file2)
  195.        DELETE(filein)
  196.        etime = TIME(E)
  197.        parse var etime secs'.'ticks
  198. CECHO('HDSearch for 'bold(filename)' completed in 'secs' sec(s)')
  199. EXIT
  200.  
  201. SEND:
  202. CHECKDATAFILE()
  203. IF DATATYPE(WORD(cmds,1))='NUM' then do;CECHO('You need to enter a Nick, then file numbers')
  204.         EXIT;END
  205.  
  206.  IF UPPER(WORD(cmds,1)) = '%U' THEN DO
  207.    "GETSELECTEDUSER";foruser=result
  208.  END
  209.  ELSE foruser = WORD(cmds,1)
  210.  cmds = SUBWORD(cmds,2)
  211.   DO UNTIL cmds = ' '
  212.    PARSE VAR cmds file','cmds
  213.      filenum = COMPRESS(file'.')
  214.      fileline = SEARCHFOR(fileout,filenum)
  215.      numwords = WORDS(fileline)
  216.      fileline = delword(fileline,numwords-1,2) 
  217.      fileline = delword(fileline,1,1)
  218.      parse var fileline filenme'--'dirpath
  219.      if words(filenme) > 1 then do
  220.         Cecho('HDSearch can''t send a file with spaces')
  221.         Cecho('I''m working on this problem.. seems it may be AmIRC')
  222.         Exit
  223.      end
  224.      fileloc = makepath(strip(dirpath),strip(filenme))
  225.      IF exists(fileloc) then do
  226.       CECHO('Sending 'bold(filepart(fileloc))' to 'foruser)
  227.       'SAY /DCC Send 'foruser fileloc
  228.      END
  229.      Else CECHO(bold(fileloc) 'does not exists')   
  230.   END
  231. EXIT
  232.  
  233. FSHOW:
  234. DO UNTIL cmds = ' '
  235.    PARSE VAR cmds file','cmds
  236.      filenum = COMPRESS(file'.')
  237.      fileline = SEARCHFOR(fileout,filenum)
  238.      'say 'bold('«HDSearch»') fileline
  239. END
  240. EXIT
  241.  
  242.  
  243. USHOW:
  244. Parse var cmds nick cmds
  245.  
  246. IF UPPER(nick) = '%U' THEN DO
  247.    "GETSELECTEDUSER";nick=result
  248. END
  249.  
  250. DO UNTIL cmds = ' '
  251.    PARSE VAR cmds file','cmds
  252.      filenum = COMPRESS(file'.')
  253.      fileline = SEARCHFOR(fileout,filenum)
  254.      'say /msg' nick fileline
  255. END
  256. EXIT
  257.  
  258.  
  259. realsize:
  260. bsize = arg(1)
  261. select
  262.  when length(bsize)~>3 then do
  263.   size='1Kb'
  264.   return size
  265.  end
  266.  when length(bsize)~>6 then do
  267.   size=trunc(bsize/1024)'Kb'
  268.   return size
  269.  end
  270.  otherwise do
  271.   size=trunc(bsize/1024)'Kb'
  272.   return size
  273.  end
  274. end
  275.  
  276. CHECKSIZE:
  277.   fl = STATEF(Filein)
  278.   filesize = WORD(fl,2)
  279.   IF filesize = 0 then do
  280.    CECHO('No files found matching 'bold(filename))
  281.    DELETE(Filein)
  282.    EXIT
  283.   END 
  284. Return 0
  285.  
  286. CHECKDATAFILE:IF ~EXISTS(fileout) THEN DO;CECHO('No Data file found');EXIT;END;RETURN 0
  287. LECHO:;"ECHO P="d2c(27)"b«"Error"» C=6" arg(1);RETURN 0
  288. CECHO:;"ECHO P="d2c(27)"b«HDSearch» C=0" arg(1);RETURN 0
  289.